//============================================================================
// Name        : ms006.cpp
// Author      : Tadas
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include "lib.h"
using namespace std;

double funk(double x)
{
	double y;
	y = x*x*x*x + x*x*x;
	return y;
}

double funk1(double x)
{
	double y;

	y = x*x - 12*x + 1;

	return y;
}

int main()
{

	int n = 0;
	double ax= -1, bx=1, cx, fa, fb, fc, ats;
	double tol = 1e-5, xmin;

	minbrak(ax, bx, cx, fa, fb, fc, funk);
	n = 0;
	ats = golden(ax, bx, cx, funk, tol, xmin, n);
	cout << n << endl;

	
	printf("f1: x^4+x^3\t Xmin: %f\tYmin: %f\n\n", xmin, ats);

	
	minbrak(ax, bx, cx, fa, fb, fc, funk1);
	n = 0;
	ats = golden(ax, bx, cx, funk1, tol, xmin, n);
	cout << n << endl;

	printf("f2: x^2-12*x+1\t Xmin: %f\t\tYmin: %f\n\n", xmin, ats);

	minbrak(ax, bx, cx, fa, fb, fc, funk);
	n = 0;
	ats = brent(ax, bx, cx, funk, tol, xmin, n);
	cout << n << endl;

	printf("Brent f1:\t Xmin: %f\tYmin: %f\n\n", xmin, ats);

	minbrak(ax, bx, cx, fa, fb, fc, funk1);
	n = 0;
	ats = brent(ax, bx, cx, funk1, tol, xmin, n);
	cout << n << endl;

	printf("Brent f2:\t Xmin: %f\t\tYmin: %f\n", xmin, ats);

	return 0;
}
